<?php

//get all category	
function getAllCategory(){
	$qr ="SELECT * FROM category";
	return mysql_query($qr);
}

//add category	
function addCategory($categoryName,$description){
	$qr ="INSERT INTO category(CategoryName,Description) VALUES('$categoryName','$description')";
	mysql_query($qr);
}

//get category by id	
function getCategoryByID($categoryID){
	$qr ="SELECT * FROM category WHERE CategoryID = $categoryID;";
	return mysql_query($qr);
}

//get category by subcategoryid
function getCategoryBySubCategoryID($subCategoryID){
	$qr ="SELECT * FROM subcategory WHERE SubCategoryID = $subCategoryID;";
	$subCategory = mysql_fetch_array(mysql_query($qr));
	$categoryID = $subCategory['CategoryID'];
	settype($categoryID,"int");
	return getCategoryByID($categoryID);
}

//get category by productid
function getCategoryByProductID($productID){
	$qr ="SELECT * FROM product WHERE ProductID = $productID;";
	$product = mysql_fetch_array(mysql_query($qr));
	$subCategoryID = $product['SubCategoryID'];
	settype($subCategoryID,"int");
	return getCategoryBySubCategoryID($subCategoryID);
}

//edit category	
function editCategory($categoryName,$description,$categoryID){
	$qr ="UPDATE category SET CategoryName = '$categoryName',Description = '$description' WHERE CategoryID = $categoryID; ";
	mysql_query($qr);
}

//edit category	amount total
function editCategoryAmountTotal($categoryAmountTotal,$categoryID){
	$qr ="UPDATE category SET CategoryAmountTotal = '$categoryAmountTotal' WHERE CategoryID = $categoryID; ";
	mysql_query($qr);
}

//delete category	
function deleteCategory($categoryID){
	$qr ="DELETE FROM category WHERE CategoryID = $categoryID";
	mysql_query($qr);
}



?>